package service

import (
	"bc/dao"
	"bc/util"
	"fmt"
)

type user struct {

}

func (u *user) Row (m map[string]interface{},page int,pageSize int) ([]*dao.Users,int) {

	d,t,e := dao.UserDao.Row(m,page,pageSize)
	if e != nil{
		panic(e)
	}
	return d,t

}
func (u *user) First(w map[string]interface{}) (*dao.Users) {
	b,d :=dao.UserDao.FirstRoleAndDp(w)
	fmt.Println(d)
	if b == true{
		return d
	}
	return nil
}
func (u *user) Del(w map[string]interface{}) bool {
	return dao.UserDao.Delete(w)
}
func (u *user) Create(d map[string]interface{}) (bool,int) {

	return dao.UserDao.Create(d)

}
func (u *user) Update(w map[string]interface{},f map[string]interface{}) bool {
	b := dao.UserDao.Update(w,f)
	return b
}
func (u *user) Auth(m map[string]interface{}) (string,int) {
	b,ud := dao.UserDao.First(m)
	if b {
		udm := map[string]interface{}{
			"uid" : ud.Uid,
			"username":ud.Username,
			"password":ud.Password,
		}
		token,err := util.GenerateToken(udm)
		if err != nil{
			panic(err)
		}
		return token, ud.Uid
	}
	return "", 0

}
var User = &user{}
